﻿//===================================================================================
// $$
//
//
// Code By: Code Milker V2
// Date On: 2013//
//===================================================================================


namespace Forest.Lion.Data.SqlServer.Repositories
{
    using System;

    using System.Collections.Generic;

    using System.Data;

    using System.Linq;
    using Forest.Lion.Model;

    public class ResumeRepository : BaseRepository, IResumeRepository
    {
        public ResumeRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }
        public void Create(Resume receipt)
        {
            this.GetDbSet<Resume>().Add(receipt);
            this.UnitOfWork.SaveChanges();
        }

        public Resume GetReceipt(Guid receiptId)
        {
            return this.GetDbSet<Resume>()
                .Where(c => c.Id == receiptId)
                .Single();
        }

        public IQueryable<Resume> All()
        {
            return this.GetDbSet<Resume>();
        }

        public void Update(Resume updatedReceipt)
        {
            this.GetDbSet<Resume>().Attach(updatedReceipt);
            this.SetEntityState(updatedReceipt, updatedReceipt.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid receiptId)
        {
            Resume receiptToDelete = this.GetReceipt(receiptId);
            this.GetDbSet<Resume>().Remove(receiptToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IEnumerable<Resume> Find()
        {
            return this.GetDbSet<Resume>().Take(100)
                .ToList();
        }

        public IEnumerable<Resume> GetAll()
        {
            return this.GetDbSet<Resume>().Take(100)
                .ToList();
        }
    }
}
